package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.entity.Student;
import com.face.server.service.AdminStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.security.Principal;

/**
 * Created by ryan on 2018/3/17.
 */
@RestController
@RequestMapping("/adminStu")
public class AdminStudentController {

    @Autowired
    private AdminStuService adminStuService;

    @GetMapping("/listStu")
    public RespMsg listStu(@PageableDefault(sort = "dormitoryBuildNum",size = 10000) Pageable pageable, @RequestParam(required = false) String key1, @RequestParam(required = false) String key2){
        return RespMsg.build(adminStuService.listStu(pageable,key1,key2));
    }

    @GetMapping("/listMyStu")
    public RespMsg listMyStu(@PageableDefault(sort = "dormitoryBuildNum",size = 10000)   Pageable pageable, @RequestParam(required =false)String key1, @RequestParam(required = false)String key2,
                             Principal principal){
        return RespMsg.build(adminStuService.listMyStu(pageable,key1,key2,principal));
    }

    @PostMapping(value = "/createStudent")
    RespMsg createStudent(@RequestBody @NotNull Student student) {
        return RespMsg.build(adminStuService.createStudent(student));
    }

    @GetMapping("/listVisitors/{id}")
    RespMsg listVisitors(@PathVariable String id,@PageableDefault Pageable pageable){
        return RespMsg.build(adminStuService.listVisitors(id,pageable));
    }

}
